package com.hxy.org.service.impl;

import com.hxy.basic.exception.BusinessExcpetion;
import com.hxy.basic.service.impl.BaseServiceImpl;
import com.hxy.org.domain.Employee;
import com.hxy.org.domain.Shop;
import com.hxy.org.mapper.EmployeeMapper;
import com.hxy.org.mapper.ShopMapper;
import com.hxy.org.service.IEmployeeService;
import com.hxy.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.swing.*;

/**
 *
 * 店铺Service接口实现类
 *
 * @authorr  Hxy
 */
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class ShopServiceImpl extends BaseServiceImpl<Shop> implements IShopService {

    @Autowired
    private ShopMapper shopMapper;
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void settlement(Shop shop) {

        Employee employee = employeeMapper.findByAccount(shop.getAdmin());
        if(employee != null){
            throw new BusinessExcpetion("入驻失败，用户信息已存在，请直接登录，忘记密码请返回");
        }

        // 店铺入驻，保存员工信息，获取id
        employeeMapper.save(shop.getAdmin());
        //保存店铺信息，并绑定管理员id
        shopMapper.save(shop);
        //在员工表绑定对应的店铺id
        employeeMapper.updateShopId(shop);
    }
}
